<?
/*  获取用户的基本信息
 *  params  uid:    用户的uid
*/
function getUserInfo($uid) {

}

/*  获取推荐位置信息列表
 *  params  part：   推荐位置(1-社区首页_资深网友推荐,2-社区首页_推荐帖子,3-博客首页_专栏推荐,4-博客首页_热门博文)
*/
function getRecommendList($part) {
  $recomm = array(
    1=>array(id=>'uid',table=>'pw_members',limit=>'0,10'),
    2=>array(id=>'id',table=>'a_pw_colonys_article',limit=>'0,10'),
    3=>array(id=>'uid',table=>'pw_members',limit=>'0,7'),
    4=>array(id=>'did',table=>'pw_diary',limit=>'0,12'),
  );
  $m = M('ARecommend');
  $ids = $m->field('type_id as id')->where('part_id = '.$part)->order('sort')->limit($recomm[$part]['limit'])->select();
  $list = array();
  foreach ($ids as $k => $v) {
    $sql = 'select * from '.$recomm[$part]['table'].' where '.$recomm[$part]['id'].' = '.$v['id'];
    $temp = $m->query($sql);
    $value = $temp[0];
    if ($part == 1 || $part == 3) $value['icon'] = formatUserIcon($value['icon']);//格式化用户头像
    if ($part == 3) {
//获取该用户最新博文
      $sql = 'select * from pw_diary where privacy = 0 and uid = '.$v['id'].' order by postdate desc limit 0,1';
      $blog = $m->query($sql);
      $value["diary_id"] = $blog[0]['did'];
      $value['diary_title'] = $blog[0]['subject'];
    }
    $list[] = $value;
  }
  return $list;
}

/*  格式化用户头像 */
function formatUserIcon($icon) {
  if(empty($icon)) {//pw8/images/face/none.gif
    $icon = "/pw8/images/face/none.gif";
  }else {
    $icons = explode('|',$icon);
    if(empty($icons[1]))
      $icon = "/pw8/images/face/none.gif";
    else {
      switch($icons[1]) {
        case 1: {
            $icon = "/pw8/images/face/".$icons[0];
          };
          break;//系统头像
        case 2:$icon = $icons[0];
          break;//网络头像
        case 3: {
            if(count($icons)>4) {
              $icons[0]=str_replace('.gif','.jpg',$icons[0]);
			  $icons[0]=str_replace('.png','.jpg',$icons[0]);
              $icon = "/pw8/attachment/upload/middle/".$icons[0];
            }
            else
              $icon = "/pw8/attachment/upload/".$icons[0];
          };
          break;//上传头像
      }
    }
  }
  return $icon;
}

//params: type  1-活跃会员，2-最新加入会员
function getMembers($type) {
  $m = M();
  if ($type == 1) {
    $sql = 'select t1.uid,t1.username,t1.icon from pw_members t1 left join pw_memberdata t2 on (t1.uid = t2.uid) order by lastvisit desc limit 0,5 ';
  }else if ($type == 2) {
    $sql = 'select uid,username,icon from pw_members order by regdate desc limit 0,5';
  }
  $list = $m->query($sql);
  foreach ($list as $k => $v) {
    $list[$k]['icon'] = formatUserIcon($list[$k]['icon']);
  }
  return $list;
}

//博客首页中的  1-最新博文，2-博文排行
function getBlogsList($type) {
  $m = M();
  if ($type == 1) {
    $sql = 'select * from pw_diary where privacy = 0 order by postdate desc limit 0,10';
  }else if ($type == 2) {
    $time = time() - 30*24*60*60;
    $sql = 'select * from pw_diary where privacy = 0 and postdate > '.$time.' order by r_num desc limit 0,10';
  }
  $list = $m->query($sql);
  return $list;
}
?>